﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Zy.WPF.CtrLib.Ctrs
{
    /// <summary>
    /// ZyPageBtn.xaml 的交互逻辑
    /// </summary>
    public partial class ZyPageBtn : UserControl,INotifyPropertyChanged
    {
        /// <summary>
        /// 页码区域单个按钮
        /// </summary>
        public ZyPageBtn()
        {
            InitializeComponent();
            this.DataContext = this;
        }
        private ICommand _btnCommand { get; set; }
        /// <summary>
        /// 窗体按钮命令
        /// </summary>
        public ICommand BtnCommand
        {
            get
            {
                return _btnCommand;
            }
            set
            {
                _btnCommand = value;
                this.NotifyPropertyChanged("BtnCommand");
            }
        }
        private int _value { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        public int Value
        {
            get { return _value; }
            set
            {
                _value = value;
                this.NotifyPropertyChanged("Value");
            }
        }
        private ZyPageBtnType _type { get; set; }=ZyPageBtnType.Normal;
        /// <summary>
        /// 类型
        /// </summary>
        public ZyPageBtnType Type
        {
            get { return _type; }
            set {
                _type = value;
                switch (this.Type)
                {
                    case ZyPageBtnType.Next:
                        Text = ">>";
                        break;
                    case ZyPageBtnType.Previous:
                        Text = "<<";
                        break;
                    case ZyPageBtnType.Last:
                        Text = ">>|";
                        break;
                    case ZyPageBtnType.Home:
                        Text = "|<<";
                        break;
                    case ZyPageBtnType.Normal:
                        Text = Value.ToString();
                        break;
                }
                this.NotifyPropertyChanged("Type");
            }
        }
        private string _text { get; set; }
        /// <summary>
        /// 显示的文字
        /// </summary>
        public string Text
        {
            get { return _text; }
            set
            {
                _text = value;
                this.NotifyPropertyChanged("Text");
            }
        }
        /// <summary>
        /// 单击事件
        /// </summary>
        private ZyPageBtn_Click _zyBtnClick { get; set; }
        /// <summary>
        /// 单击事件
        /// </summary>
        public ZyPageBtn_Click ZyBtnClick
        {
            get => _zyBtnClick;
            set
            {
                _zyBtnClick = value;
                this.NotifyPropertyChanged("ZyBtnClick");
            }
        }
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler? PropertyChanged;
        /// <summary>
        /// 属性改变
        /// </summary>
        /// <param name="propName"></param>
        public void NotifyPropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
        #endregion
        /// <summary>
        /// 按钮点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pageBtn_Click(object sender, RoutedEventArgs e)
        {
            if (ZyBtnClick != null&&Type!=ZyPageBtnType.Current)
            {
                ZyBtnClick(this.Value);
            }
        }
        /// <summary>
        /// 单击事件
        /// </summary>
        /// <param name="value"></param>
        public delegate void ZyPageBtn_Click(int value);
    }
    /// <summary>
    /// 页面按钮样式
    /// </summary>
    public enum ZyPageBtnType
    {
        /// <summary>
        /// 上一页
        /// </summary>
        Previous,
        /// <summary>
        /// 下一页
        /// </summary>
        Next,
        /// <summary>
        /// 当前页
        /// </summary>
        Current,
        /// <summary>
        /// 正常页
        /// </summary>
        Normal,
        /// <summary>
        /// 首页
        /// </summary>
        Home,
        /// <summary>
        /// 末页
        /// </summary>
        Last
    }
}
